<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
    FB.init({appId: '164726177047059', status: true, cookie: true, xfbml: true});
    FB.getLoginStatus(function(response) {
      if (response.status === 'connected') {
        // the user is logged in and has authenticated your
        // app, and response.authResponse supplies
        // the user's ID, a valid access token, a signed
        // request, and the time the access token
        // and signed request each expire
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        document.getElementById('fbuser').innerHTML = uid;
        document.getElementById('uid').value = uid;
        document.getElementById('profilepic').innerHTML = '<img src="http://graph.facebook.com/'+uid+'/picture"/>';
        //document.getElementById('fbbt').innerHTML = "<input type='submit' value='Process'/>";
        window.location = "checkfb/"+uid;
      } else if (response.status === 'not_authorized') {
        // the user is logged in to Facebook,
        // but has not authenticated your app
        document.getElementById('fbuser').innerHTML = "คุณยังไม่ได้อนุญาตการเชื่อมต่อกับ Facebook"
      } else {
        document.getElementById('fbuser').innerHTML = "คุณยังไม่ได้ login เข้าสู่ Facebook"
      }
    });
    FB.Event.subscribe('auth.login', function(response) {
        var uid = response.authResponse.userID;
        var accessToken = response.authResponse.accessToken;
        document.getElementById('fbuser').innerHTML = uid;
        document.getElementById('uid').value = uid;
        document.getElementById('profilepic').innerHTML = '<img src="http://graph.facebook.com/'+uid+'/picture"/>';
        //document.getElementById('fbbt').innerHTML = "<input type='submit' value='Process'/>";
        window.location = "checkfb/"+uid;
    });
</script>
<div class='form'>
<div class='box'>กรุณา login เพื่อเข้าใช้งาน</div>
<table>
  <tr>
    <td>
      <form action="/users/authenticate/form" method="post">
          รหัสผู้ใช้:
          <input id="username" name="username" type="text" />
          <p></p>
          รหัสผ่าน:
          <input id="password" name="password" type="password" />
          <input id="sid" name="sid" type="hidden" value="f5a3586a6cb379001f89d8e86ad860de" />
          <input id="callback" name="callback" type="hidden" />
          <p></p>
          <div class='div' style='margin-left:90px;'><input name="commit" type="submit" value="Login" /></div>
      </form>      
    </td>
    <td width="100px"></td>
    <td>
      <form action="/users/process_login" method="post">
        <table width="85%">
          <tr>
            <td>UID: </td>
            <td><span id="fbuser"></span><input type="hidden" name="uid" id="uid"/><br/><span id="profilepic"></span></td>
          </tr>
          <tr>
            <td colspan="2">
              <span id="fbbt">
                <fb:login-button>Facebook Login</fb:login-button>
              </span>
            </td>
          </tr>
        </table>
        </form>
    </td>
  </tr>
</table>
  <script>
    $('#username').focus();
  </script>
</div>
<p></p>
<!--a href="/users/forgot_password">ลืมรหัสผ่าน</a-->
<!-- = session[:app] -->